﻿using HalalCheck.Resources;
using HalalCheck.ViewModels;
using SpotOffer.Resource;
using Xamarin.Forms;
using XLabs.Forms.Controls;
using XLabs.Forms.Mvvm;

namespace HalalCheck.View
{
    public partial class MenuPage : BaseView
    {
        public ListView MenuListView { get; set; }

        public MenuPage()
        {
            Title = HalalStrings.Choose;
            Icon = "settings.png";
         //   Title = "Halal Check"; // The Title property must be set.

			var layout = new RelativeLayout {
				VerticalOptions = LayoutOptions.FillAndExpand,
				HorizontalOptions = LayoutOptions.FillAndExpand,
			};
			var halalchecklogo = new Image
			{
				Source = "centerlogo.png"
			};
			layout.Children.Add(halalchecklogo, Constraint.RelativeToParent((p) => (p.Bounds.Width - 200) / 2), Constraint.RelativeToParent((p) => (p.Bounds.Height - 200) / 2), Constraint.RelativeToParent((p => 200)), Constraint.RelativeToParent((p) => 200));


            BackgroundColor = AppColors.OrigDarkBlue;

            MenuListView = new ListView
            {
                RowHeight = 60,
                ItemTemplate = new DataTemplate(MakeHalalItemLayout),
				BackgroundColor = AppColors.OrigDarkBlue.MultiplyAlpha(0.8),
                SeparatorVisibility = SeparatorVisibility.None
            };
            MenuListView.SetBinding(ListView.ItemsSourceProperty, new Binding("MenuData"));

         
     
			layout.Children.Add(MenuListView,Constraint.Constant(0),Constraint.Constant(0),Constraint.RelativeToParent((p)=>p.Bounds.Width),Constraint.RelativeToParent((p)=>p.Bounds.Height));
         

            Content = layout;
        }

        public NavigationPage Nav { get; set; }


        private ViewCell MakeHalalItemLayout()
        {
            var itemLayout = new RelativeLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.Start,
                Padding = new Thickness(5, 5, 5, 5),
            };

            var menuIcon = new Image();
            menuIcon.SetBinding(Image.SourceProperty, "IconSource");

            itemLayout.Children.Add(menuIcon, Constraint.Constant(AppMargins.ItemPadding), Constraint.Constant(AppMargins.ItemPadding), Constraint.RelativeToParent((p) => p.Bounds.Height - AppMargins.ItemPadding * 2), Constraint.RelativeToParent((p) => p.Bounds.Height - AppMargins.ItemPadding * 2));

            var menuLabel = new ExtendedLabel
            {
                XAlign = TextAlignment.Start,
                YAlign = TextAlignment.Center,
				FontSize = (Device.GetNamedSize(NamedSize.Large, typeof(Label)))*1.2,
                FontAttributes = FontAttributes.Bold,
                TextColor = AppColors.White,
                LineBreakMode = LineBreakMode.TailTruncation,
                //FontName = "Harabara.otf",
            };
            menuLabel.SetBinding(Label.TextProperty, "Title");

            itemLayout.Children.Add(menuLabel, Constraint.RelativeToView(menuIcon, (p, s) => s.Bounds.Right + AppMargins.ItemPadding), Constraint.Constant(AppMargins.ItemPadding), null, Constraint.RelativeToParent((p) => p.Bounds.Height - AppMargins.ItemPadding * 2));
            return new ViewCell
            {
                View = itemLayout
            };
        }


    }
}